import JSEncrypt from 'jsencrypt/bin/jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDu+0d3N2VxZ39eM2tqXjiIxNkWPQcOkvtAhPwRXExiEw1oG3Qllejxf/4b72CTX7mNfgQV7hVBaIkCv836tcbAeS14CKEibYg41x5b9+koo/r755My8q/YCp72yLkq/KpMAQw6t66eLI0BayWiOvXwjG5Ii8lSjJZkxm/qTCNgiQIDAQAB';

const privateKey = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAO77R3c3ZXFnf14z\n' +
    'a2peOIjE2RY9Bw6S+0CE/BFcTGITDWgbdCWV6PF//hvvYJNfuY1+BBXuFUFoiQK/\n' +
    'zfq1xsB5LXgIoSJtiDjXHlv36Sij+vvnkzLyr9gKnvbIuSr8qkwBDDq3rp4sjQFr\n' +
    'JaI69fCMbkiLyVKMlmTGb+pMI2CJAgMBAAECgYBtwpMsOhEpaLOi/FLVY7jreB2M\n' +
    'jTL0iqVDGND82Dtsv/tkWVea+6MlZ/e5tNPSXCDIz5voxpSUmgJzdMyR3XMOiFsz\n' +
    '1iqKHQ3P8oFF1UYeDg0pm+sZXNssLVz21ywMV63CJmEa8FokH30/s306QWB3Gpf+\n' +
    'yzzii5EpYgXPn6ZWUQJBAPvbbfn4o/WcxhN9QybFYKFdcjRG8hkqhqv0jyZsMb+G\n' +
    '+E0IAIbV0wEB8XfkWhyodjJI+lQFg1JUwf02O6qgeLMCQQDy6aFmejl6vncmaazz\n' +
    'vQv7CRyfj26J8Y98UkHnm9X/Gg7YfgHo0UVsgnZPVs0upKIHAjgchIRp9G/DWMMq\n' +
    'oQfTAkBXFuuSkr3vgoSj3J7J21qssel51kaFGUV0VJ7jhGo3dm6KBIhaF7pdENT0\n' +
    'xku6uS4V+VJGl5lvcMubyZMcT10tAkBiKLy6/3sIubzGPf/Qwrz7pXP2mmxNu9qC\n' +
    'n27YW+W+31XOcCTvYtmN/q42Y1oolgiPknsAMyCa/FbJdq3vJQFXAkEAwa6hJcJX\n' +
    'iV7Su/v8Z8wI5uYCSPV3IaIvLWeVM6GIFOz13j1E3i6KNODUEHOn/rpiXGIR/WAX\n' +
    '+aWeC4xeX0SdcQ=='

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey('-----BEGIN PUBLIC KEY-----' + publicKey + '-----END PUBLIC KEY-----') // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey('-----BEGIN RSA PRIVATE KEY-----' + privateKey + '-----END RSA PRIVATE KEY-----') // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}

